const User = require('../model/user.model')
class UserService {
    // 注册
    async createUser(userName, password) {
        // 写入数据库
       const res = await User.create({
            userName,
            password
        })
        return res.dataValues
    }
    async upDataInfo(param, id) {
        User.update(param, {where: { id }})
    }
    // 获取用户信息
    async getUserInfo({ id, userName, password, userType }) {
        const whereOpt = {}
        id && Object.assign(whereOpt, { id })
        userName && Object.assign(whereOpt, { userName })
        password && Object.assign(whereOpt, { password })
        userType && Object.assign(whereOpt, { userType })
        const res =  await User.findOne({
            attributes: ['id', 'userName', 'password', 'userType'],
            where: whereOpt
        })
        return res ? res.dataValues : null
    }
}
module.exports = new UserService()
